package com.zhao.test;

import java.util.concurrent.Callable;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.task.AsyncTaskExecutor;

import com.zhao.service.task.AsyncRunnable;
import com.zhao.service.task.AsyncTask;

public class AsyncRunnerTesting extends UnitTesting {

	@Autowired
	AsyncTask asyncTask;

	@Autowired
	AsyncTaskExecutor asyncTaskExecutor;

	@Test
	public void contextLoads() {

	}

	/**
	 * 
	 */
	@Test
	public void testAsyncAnnotation() {
		try {
			logger.debug("{}开始执行 ", Thread.currentThread().getName());
			asyncTask.exec();
			logger.debug("{}结束执行 ", Thread.currentThread().getName());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Test
	public void testAsyncTaskExecutor() {
		try {
			asyncTaskExecutor.execute(new AsyncRunnable());
			asyncTaskExecutor.submit(new Callable<String>() {
				@Override
				public String call() throws Exception {
					logger.debug("{}执行回调 ", Thread.currentThread().getName());
					return "";
				}

			});
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
